package com.ruoyi.other.api;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.other.pojo.AppUserLogoutDTO;
import com.ruoyi.other.pojo.AppUserThirdDTO;
import com.ruoyi.other.service.AppOtherService;
import com.ruoyi.user.domain.UserJoin;

import io.swagger.annotations.Api;

@RestController
@RequestMapping("/api/v1/other")
@Api(tags = "【APP】平台其他接口")
@CrossOrigin
public class AppOtherController {

	@Autowired
	private AppOtherService appOtherService;
	
	/**
	 * 	获取版本号
	 * @param request
	 * @return
	 */
//	@GetMapping(value = "/getAppVersion")
//	public AjaxResult getAppVersion(HttpServletRequest request) {
//		String deviceName = request.getHeader("deviceName");
//		Integer versionCode = request.getIntHeader("versionCode");
//		return appOtherService.getAppVersion(deviceName, versionCode);
//	}
	
	
	/**
	 * 	获取注销原因
	 * @return
	 */
	@GetMapping(value = "/getLogoutType")
	public AjaxResult getLogoutType(HttpServletRequest request) {
		return appOtherService.getLogoutType(request);
	}
	
	/**
	 * 	确认注销
	 * @param loginUserId
	 * @return
	 */
	@PostMapping(value = "/confirmLogout")
	public AjaxResult confirmLogout(@RequestBody AppUserLogoutDTO userLogout,HttpServletRequest request) {
		if(null == userLogout || StringUtils.isEmpty(userLogout.getLogoutType()) || StringUtils.isEmpty(userLogout.getLogoutContent())) {
			return AjaxResult.error("请输入注销原因");
		}
//		if(StringUtils.isEmpty(userLogout.getMobileCode())) {
//			return AjaxResult.error("请输入验证码");
//		}
		return appOtherService.confirmLogout(userLogout,request);
	}
	
	/**
	 * 	账号管理 
	 *  手机号码、微信、支付宝
	 * @return
	 */
	@GetMapping(value = "/getAccountManage")
	public AjaxResult getAccountManage(HttpServletRequest request) {
		return appOtherService.getAccountManage(request);
	}
	
	/**
	 * 	绑定支付宝账号
	 * @param userThird
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/bindAlipay")
	public AjaxResult bindAlipay(@RequestBody AppUserThirdDTO userThird,HttpServletRequest request) {
		if(null == userThird || StringUtils.isEmpty(userThird.getAlipayAccount()) || StringUtils.isEmpty(userThird.getAlipayUserName())) {
			return AjaxResult.error("请输入支付宝账号");
		}
		return appOtherService.bindAlipay(userThird,request);
	}
	
	/**
	 * 	绑定微信账号
	 * @param userThird
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/bindWechat")
	public AjaxResult bindWechat(@RequestBody AppUserThirdDTO userThird,HttpServletRequest request) {
		if(null == userThird || StringUtils.isEmpty(userThird.getCode())) {
			return AjaxResult.error("请授权微信");
		}
		return appOtherService.bindWechat(userThird,request);
	}
	
	/**
	 * 	获取真人验证TOKEN 
	 * @return
	 */
	@GetMapping(value = "/getRealNameToken")
	public AjaxResult getRealNameToken(HttpServletRequest request) {
		return appOtherService.getRealNameToken(request);
	}
	
	/**
	 * 	认证完成 前端回调接口
	 * @return
	 */
	@GetMapping(value = "/authPass")
	public AjaxResult authPass(HttpServletRequest request) {
		return appOtherService.authPass(request);
	}
	
	/**
	 * 	赠送礼物
	 * @param toUserId		对方ID
	 * @param businessId	礼物ID
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/giveGift")
	public AjaxResult giveGift(Long toUserId,Long businessId,HttpServletRequest request) {
		if(null == toUserId) {
			return AjaxResult.error("请选择用户");
		}
		if(null == businessId) {
			return AjaxResult.error("请选择礼物");
		}
		return appOtherService.giveGift(toUserId, businessId, request);
	}
	
	/**
	 * 	赠送礼物流水
	 * @param pageNo
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/giveGiftFlow")
	public AjaxResult giveGiftFlow(Integer pageNo,HttpServletRequest request) {
		if(null == pageNo) {
			pageNo = 1;
		}
		return appOtherService.giveGiftFlow(pageNo, request);
	}
	
	/**
	 * 	收到礼物流水
	 * @param pageNo
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/receiveGiftFlow")
	public AjaxResult receiveGiftFlow(Integer pageNo,HttpServletRequest request) {
		if(null == pageNo) {
			pageNo = 1;
		}
		return appOtherService.receiveGiftFlow(pageNo, request);
	}
	
	/**
	 * 	发起语音通话校验余额
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/sendVoiceCallCheck")
	public AjaxResult sendVoiceCallCheck(Integer toUserId,HttpServletRequest request) {
		return appOtherService.sendVoiceCallCheck(toUserId,request);
	}
	
	/**
	 * 	添加加盟
	 * @param join
	 * @return
	 */
	@PostMapping(value = "/submitJoin")
	public AjaxResult submitJoin(@RequestBody UserJoin join) {
		Assert.notNull(join,"请输入数据");
		if(StringUtils.isEmpty(join.getPhone())) return AjaxResult.error("请输入手机号码");
		if(StringUtils.isEmpty(join.getWechat())) return AjaxResult.error("请输入微信号");
		if(StringUtils.isEmpty(join.getContent())) return AjaxResult.error("请输入意向");
		//return appOtherService.submitJoin(join);
		return AjaxResult.success();
	}
	
	
}
